home *** CD-ROM | disk | FTP | other *** search
- Subject: v07i068: Image manipulation routines in C++, Part05/05
- Newsgroups: mod.sources
- Approved: mirror!rs
-
- Submitted by: David Sher <seismo!rochester!sher>
- Mod.sources: Volume 7, Issue 68
- Archive-name: image/Part05
-
- [ The Makefiles had ESCAPE and \r characters in their comment lines;
- I changed them to their printable representation, the two-character
- sequences ^[ and ^M, respectively. Also, the file ascii2var/uu.test.var
- had some non-ASCII characters in it; I used uuencode; the resultant
- file is really ascii2var/test.var. Also, I do not have C++ nor any
- images, so I have not tested this package. --r$ ]
-
- #!/bin/sh
- # This is a shell archive. Remove anything before this line,
- # then unpack it by saving it in a file and typing "sh file".
- # If all goes well, you will see the message "No problems found."
- # Wrapped by mirror!rs on Mon Nov 10 13:45:52 EST 1986
-
- # Exit status; set to 1 on "wc" errors or if would overwrite.
- STATUS=0
- # Contents: vartools/makefile vartools/vartools.h++
- # vartools/vartools.h vartools/cap.c++ MANIFEST
-
- echo x - vartools/makefile
- if test -f vartools/makefile ; then
- echo vartools/makefile exists, putting output in $$vartools/makefile
- OUT=$$vartools/makefile
- STATUS=1
- else
- OUT=vartools/makefile
- fi
- sed 's/^X//' > $OUT <<'@//E*O*F vartools/makefile//'
- X# this is the makefile for the vartools library
-
- X# This line constructs the library name (equal to the directory name)
- X# jccpwd^[!!sh^M:s/.*\///g^MILIBRARY = lib^[A.a^[
- XLIBRARY = libvartools.a
-
- X.SUFFIXES: .c++
-
-
- XCFLAGS = -O -I/usr/grads/include
-
- XC++FLAGS = -Fi $(CFLAGS)
-
- XLIBS = -liff -lC
-
- X# This line constructs the list of possible objects
- X# 2jc}ls *[A-Za-z0-9].c *.c++^[!!sh^M>}>}:g/\.c\+*$/ s//.o \\/^M
- XOBJS = \
- X ascii2var.o \
- X cap.o \
- X correlate.o \
- X scale.o \
- X trunc.o \
- X var2ascii.o
-
-
- X.c++.o:
- X c++ -c $(C++FLAGS) $*.c++
-
- X# the library is constructed by this line
- X$(LIBRARY) : $(OBJS)
- X ar qv $(LIBRARY) $(OBJS)
- X ranlib $(LIBRARY)
-
- @//E*O*F vartools/makefile//
- chmod u=rw,g=r,o=r $OUT
-
- echo x - vartools/vartools.h++
- if test -f vartools/vartools.h++ ; then
- echo vartools/vartools.h++ exists, putting output in $$vartools/vartools.h++
- OUT=$$vartools/vartools.h++
- STATUS=1
- else
- OUT=vartools/vartools.h++
- fi
- sed 's/^X//' > $OUT <<'@//E*O*F vartools/vartools.h++//'
- X/*
- X This is the header file for all the utilities supplied
- X in the vartools library
-
- X assumes that stdio.h has been included
- X*/
- X#ifndef VARTOOLS_H
- X#define VARTOOLS_H
-
- X// needs this include file to have the image routines definition make sense
- X#include <double_image.h++>
- X#include <long_image.h++>
-
- X/*
- X This routine gets information from an iff file and constructs
- X a var file from it
- X comments is a null terminated string that sets up the
- X comments for the var file
- X*/
- Xvoid
- Xiff2var(FILE *iff_file, FILE *var_file, char *comments);
-
- X/*
- X This routine gets information from a var file and constructs
- X an iff file from it.
- X This only works with graytone (integer) var files
- X To make a double var file into a graytone one use trunc
- X*/
- Xvoid
- Xvar2iff(FILE *var_file, FILE *iff_file);
-
- X/*
- X This converts a file in ascii format to a double var file
- X ascii format is 2 dimensions followed by an appropriate number
- X of doubles followed by comments
- X input is a file pointer to the input file
- X output is a file pointer open for output
- X*/
- Xvoid
- Xascii2var(FILE *input , FILE *output);
-
- X/*
- X This takes an initialized double image and outputs a file in ascii format
- X described above
- X input is an initialized image
- X output is a file pointer open for output
- X format is the format to output each number
- X*/
- Xvoid
- Xvar2ascii2(double_image& input , FILE *output , char *format );
-
- X/*
- X This is a version of var2ascii that takes an input file rather
- X than an initialized image
- X*/
- Xvoid
- Xvar2ascii(FILE *input, FILE *output , char *format);
-
- X/*
- X Truncates an input image (takes floating point to long)
- X needs a file to be output to
- X but does not write to file
- X instead returns the truncated image
- X*/
- Xlong_image&
- Xtrunc2( double_image& input , FILE *outfile );
-
- X/*
- X Truncates a double image into a graytone (integer image)
- X Takes two files and reads from one to write to the other
- X comment is a comment to be placed on the image
- X*/
- Xvoid
- Xtrunc( FILE *infile , FILE *outfile, char *comment);
-
- X/*
- X This takes an image as input and creates another
- X It takes every pixel of the image and multiplies it by the
- X scale and then adds to it the increment.
- X*/
- Xdouble_image&
- Xscale2(double scale, double increment, double_image& input, FILE *output_file);
-
- X/*
- X This takes two files and takes one and puts
- X a scaled and incremented version into the other
- X comment will be placed in the comment for the output image
- X*/
- Xvoid
- Xscale(double scale, double increment, FILE *input, FILE *output, char * comment);
-
- X/*
- X this one takes 2 images and returns an image containing the
- X correlation of the input image with the template image
- X it only returns values for the point where the template lies
- X entirely within the input
- X*/
- Xdouble_image&
- Xcorrelate2(double_image& template, double_image& input, FILE *output_file);
-
- X/*
- X this one takes 2 image files and returns an image file containing the
- X correlation of the input image with the template image
- X it only returns values for the point where the template lies
- X entirely within the input
- X*/
- Xvoid
- Xcorrelate(FILE *template_file, FILE *input_file, FILE *output_file, char *comment);
-
- X/*
- X This code places an upper bound on the values of the pixels.
- X If a pixel exceeds the bound it is set to the bound.
- X*/
- Xdouble_image&
- Xupper_bound2(double bound, double_image& input, FILE * output_file);
-
- X/*
- X This code places an lower bound on the values of the pixels.
- X If a pixel exceeds the bound it is set to the bound.
- X*/
- Xdouble_image&
- Xlower_bound2(double bound, double_image& input, FILE * output_file);
-
- X/*
- X This code is like upper_bound2 but with files (for C)
- X*/
- Xvoid
- Xupper_bound(double bound, FILE * input_file, FILE * output_file, char *comment);
-
- X/*
- X This code is like lower_bound2 but with files (for C)
- X*/
- Xvoid
- Xlower_bound(double bound, FILE * input_file, FILE * output_file, char *comment);
-
- X#endif VARTOOLS_H
- X/*
- XCopyright (C) 1986, David Sher in the University of Rochester
- XPermission is granted to any individual or institution to use, copy, or
- Xredistribute this software so long as it is not sold for profit, provided
- Xthis copyright notice is retained.
- X*/
- @//E*O*F vartools/vartools.h++//
- chmod u=rw,g=r,o=r $OUT
-
- echo x - vartools/vartools.h
- if test -f vartools/vartools.h ; then
- echo vartools/vartools.h exists, putting output in $$vartools/vartools.h
- OUT=$$vartools/vartools.h
- STATUS=1
- else
- OUT=vartools/vartools.h
- fi
- sed 's/^X//' > $OUT <<'@//E*O*F vartools/vartools.h//'
- X/*
- X This is the header file for all the utilities supplied
- X in the vartools library
-
- X assumes that stdio.h has been included
- X*/
- X#ifndef VARTOOLS_H
- X#define VARTOOLS_H
-
-
- X/*
- X This routine gets information from an iff file and constructs
- X a var file from it
- X comments is a null terminated string that sets up the
- X comments for the var file
- X*/
- Xvoid
- Xiff2var(/* FILE *iff_file, FILE *var_file, char *comments */);
-
- X/*
- X This routine gets information from a var file and constructs
- X an iff file from it.
- X This only works with graytone (integer) var files
- X To make a double var file into a graytone one use trunc
- X*/
- Xvoid
- Xvar2iff(/* FILE *var_file, FILE *iff_file */);
-
- X/*
- X This converts a file in ascii format to a double var file
- X ascii format is 2 dimensions followed by an appropriate number
- X of doubles followed by comments
- X input is a file pointer to the input file
- X output is a file pointer open for output
- X*/
- Xvoid
- Xascii2var(/* FILE *input , FILE *output */);
-
- X/*
- X This takes an initialized double image and outputs a file in ascii format
- X described above
- X*/
- Xvoid
- Xvar2ascii(/* FILE *input, FILE *output , char *format */);
-
-
- X/*
- X Truncates a double image into a graytone (integer image)
- X Takes two files and reads from one to write to the other
- X comment is a comment to be placed on the image
- X*/
- Xvoid
- Xtrunc(/* FILE *infile , FILE *outfile, char *comment */);
-
- X/*
- X This takes an image file as input and creates another
- X It takes every pixel of the image and multiplies it by the
- X scale and then adds to it the increment.
- X*/
- Xvoid
- Xscale(/* double scale, double increment, FILE *input, FILE *output, char * comment */);
-
- X/*
- X This routine takes in a file for the template and a file for the
- X input and outputs a file for the result of correlating the template
- X with the image. It only gets values for points where the template
- X lies entirely within the input image.
- X Comment will be placed within the comments.
- X*/
- Xvoid
- Xcorrelate(/* FILE *template_file, FILE *input_file, FILE *output_file, char *comment */);
-
- X/*
- X This code places an upper bound on the values of the pixels.
- X If a pixel exceeds the bound it is set to the bound.
- X*/
- Xvoid
- Xupper_bound(/* double bound, FILE * input_file, FILE * output_file, char *comment */);
-
- X/*
- X This code places an lower bound on the values of the pixels.
- X If a pixel exceeds the bound it is set to the bound.
- X*/
- Xvoid
- Xlower_bound(/* double bound, FILE * input_file, FILE * output_file, char *comment */);
-
- X#endif VARTOOLS_H
- @//E*O*F vartools/vartools.h//
- chmod u=rw,g=r,o=r $OUT
-
- echo x - vartools/cap.c++
- if test -f vartools/cap.c++ ; then
- echo vartools/cap.c++ exists, putting output in $$vartools/cap.c++
- OUT=$$vartools/cap.c++
- STATUS=1
- else
- OUT=vartools/cap.c++
- fi
- sed 's/^X//' > $OUT <<'@//E*O*F vartools/cap.c++//'
- X/*
- X This is the routines that take the pixels of an image and place an
- X upper or lower bound on them.
- X*/
-
- X#include <stream.h>
- X#include <stdio.h>
- X#include <string.h>
- X#include <double_image.h++>
- X#include <vartools.h++>
-
- X/*
- X This code places an upper bound on the values of the pixels.
- X If a pixel exceeds the bound it is set to the bound.
- X*/
- Xdouble_image&
- Xupper_bound2(double bound, double_image& input, FILE * output_file)
- X {
- X // create the image
- X double_image *output_pointer =
- X new double_image(CREATE,input.n_rows(),input.n_cols(),output_file);
- X double_image& output = *output_pointer;
- X // iterate through the images copying when it is a good idea
- X while(++input,++output)
- X {
- X double pixel = input();
- X output() = (pixel > bound) ? bound : pixel;
- X }
-
- X return output;
- X }
-
- X/*
- X This code places an lower bound on the values of the pixels.
- X If a pixel exceeds the bound it is set to the bound.
- X*/
- Xdouble_image&
- Xlower_bound2(double bound, double_image& input, FILE * output_file)
- X {
- X // create the image
- X double_image *output_pointer =
- X new double_image(CREATE,input.n_rows(),input.n_cols(),output_file);
- X double_image& output = *output_pointer;
- X // iterate through the images copying when it is a good idea
- X while(++input,++output)
- X {
- X double pixel = input();
- X output() = (pixel < bound) ? bound : pixel;
- X }
-
- X return output;
- X }
-
-
- X/*
- X This code is like upper_bound2 but with files (for C)
- X*/
- Xvoid
- Xupper_bound(double bound, FILE * input_file, FILE * output_file, char *comment)
- X {
- X // read in the input image
- X double_image input(READ,input_file);
- X // apply the upper bound to it and get the output
- X double_image& output = upper_bound2(bound,input,output_file);
- X // set up the comments
- X output.set_comments(comment,strlen(comment));
- X char *string = form("Applying Upper Bound of %e to image:\n",bound);
- X output.add_comment(string,strlen(string));
- X output.add_comment((char *) input.the_comments(),input.c_length());
- X // write the result to file
- X output.write();
- X }
-
- X/*
- X This code is like lower_bound2 but with files (for C)
- X*/
- Xvoid
- Xlower_bound(double bound, FILE * input_file, FILE * output_file, char *comment)
- X {
- X // read in the input image
- X double_image input(READ,input_file);
- X // apply the upper bound to it and get the output
- X double_image& output = lower_bound2(bound,input,output_file);
- X // set up the comments
- X output.set_comments(comment,strlen(comment));
- X char *string = form("Applying Lower Bound of %e to image:\n",bound);
- X output.add_comment(string,strlen(string));
- X output.add_comment((char *) input.the_comments(),input.c_length());
- X // write the result to file
- X output.write();
- X }
-
- X/*
- XCopyright (C) 1986, David Sher in the University of Rochester
- XPermission is granted to any individual or institution to use, copy, or
- Xredistribute this software so long as it is not sold for profit, provided
- Xthis copyright notice is retained.
- X*/
- @//E*O*F vartools/cap.c++//
- chmod u=rw,g=r,o=r $OUT
-
- echo x - MANIFEST
- if test -f MANIFEST ; then
- echo MANIFEST exists, putting output in $$MANIFEST
- OUT=$$MANIFEST
- STATUS=1
- else
- OUT=MANIFEST
- fi
- sed 's/^X//' > $OUT <<'@//E*O*F MANIFEST//'
- XMANIFEST 5
- XREADME 1
- Xascii2var 1
- Xascii2var/main.c++ 1
- Xascii2var/makefile 1
- Xascii2var/uu.test.var 1
- Xcopywrite 1
- Xcorrelate 1
- Xcorrelate/main.c++ 1
- Xcorrelate/makefile 1
- Xlowerbound 1
- Xlowerbound/main.c++ 1
- Xlowerbound/makefile 1
- Xman 1
- Xman/ascii2var.1 1
- Xman/correlate.1 2
- Xman/iff2var.1 1
- Xman/image.5 1
- Xman/lowerbound.1 2
- Xman/scale.1 2
- Xman/truncate.1 2
- Xman/upperbound.1 2
- Xman/var2ascii.1 2
- Xman/var2iff.1 1
- Xman/vartools.3 2
- Xscale 1
- Xscale/main.c++ 2
- Xscale/makefile 2
- Xtruncate 1
- Xtruncate/main.c++ 2
- Xtruncate/makefile 2
- Xupperbound 1
- Xupperbound/main.c++ 2
- Xupperbound/makefile 2
- Xvar2ascii 1
- Xvar2ascii/main.c++ 2
- Xvar2ascii/makefile 2
- Xvarc++ 1
- Xvarc++/archive.h++ 2
- Xvarc++/bitio.h++ 2
- Xvarc++/char_image.h++ 2
- Xvarc++/double_image.c++ 4
- Xvarc++/double_image.h++ 3
- Xvarc++/error.h++ 2
- Xvarc++/for.h++ 3
- Xvarc++/iff_image.h++ 3
- Xvarc++/iff_local.h++ 3
- Xvarc++/iff_stdim.h++ 3
- Xvarc++/image.c++ 4
- Xvarc++/image.c.old 4
- Xvarc++/image.h++ 3
- Xvarc++/long_image.c++ 4
- Xvarc++/long_image.h++ 3
- Xvarc++/makefile 3
- Xvarc++/var.h++ 3
- Xvarc++/var_double_image.c++ 3
- Xvarc++/var_image.c++ 3
- Xvarc++/var_long_image.c++ 3
- Xvartools 1
- Xvartools/README 3
- Xvartools/ascii2var.c++ 3
- Xvartools/cap.c++ 5
- Xvartools/correlate.c++ 4
- Xvartools/makefile 5
- Xvartools/scale.c++ 4
- Xvartools/trunc.c++ 4
- Xvartools/var2ascii.c++ 3
- Xvartools/vartools.h 5
- Xvartools/vartools.h++ 5
- @//E*O*F MANIFEST//
- chmod u=rw,g=rw,o=rw $OUT
-
- echo Inspecting for damage in transit...
- temp=/tmp/sharin$$; dtemp=/tmp/sharout$$
- trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
- cat > $temp <<\!!!
- 34 93 641 makefile
- 142 661 4189 vartools.h++
- 87 425 2548 vartools.h
- 98 382 2994 cap.c++
- 69 138 2143 MANIFEST
- 430 1699 12515 total
- !!!
- wc vartools/makefile vartools/vartools.h++ vartools/vartools.h vartools/cap.c++ MANIFEST | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
- if test -s $dtemp ; then
- echo "Ouch [diff of wc output]:"
- cat $dtemp
- STATUS=1
- elif test $STATUS = 0 ; then
- echo "No problems found."
- else
- echo "WARNING -- PROBLEMS WERE FOUND..."
- fi
- exit $STATUS
-